﻿#!/usr/bin/env python3

import threading
import time
import logging

def daemonFunc():
    logging.debug("starting")
    time.sleep(1)
    logging.debug("over")   #若无d.join(), 该句不会输出.

def nondaemonFunc():
    logging.debug("starting")
    logging.debug("over")


def main():
    '''
daemon是一种特殊的thread, 它不会影响主程序(进程)的退出.

'''
    logging.basicConfig(
        level = logging.DEBUG,
        format='(%(threadName)-10s) %(message)s'
    )
    d = threading.Thread(name="daemon", target=daemonFunc, daemon=True)
    n = threading.Thread(name="nondaemon", target=nondaemonFunc)

    d.start()
    n.start()

    #d.join()
    #n.join()



if __name__=='__main__':
    main()
